package com.cjy.common.utils;

/**
 * @author Cheng JiYe
 * @description:
 * @date 2020/6/6  14:46
 */
@SuppressWarnings("ALL")
public class StringUtils extends org.apache.commons.lang3.StringUtils {
    /**
     * 是否为null或空字符串
     *
     * @param val
     * @return
     */
    public static boolean isBlank(Object val) {
        if (val == null) {
            return true;
        } else if (val instanceof String) {
            return isBlank(val.toString());
        }

        return false;
    }

    /**
     * 是否不为null或空字符串
     *
     * @param val
     * @return
     */
    public static boolean isNotBlank(Object val) {
        return !isBlank(val);
    }

    /**
     * 默认字符串
     *
     * @param val
     * @return
     */
    public static String defaultString(Object val) {
        return val == null ? "" : val.toString();
    }

    /**
     * 字符串转ASCII
     *
     * @param value
     * @return
     */
    public static String stringToAscii(String value) {
        StringBuffer sbu = new StringBuffer();
        char[] chars = value.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (i != chars.length - 1) {
                sbu.append((int) chars[i]).append(",");
            } else {
                sbu.append((int) chars[i]);
            }
        }
        return sbu.toString();
    }

    /**
     * 默认字符串
     *
     * @param val
     * @return
     */
    public static String defaultStringNull(Object val) {
        return val == null ? null : val.toString();
    }

    /**
     * 左补齐
     *
     * @param str    待补齐字符串
     * @param padStr 用于补齐的字符串
     * @param len    总长度
     * @return
     */
    public static String lpadStr(String str, String padStr, int len) {
        while (str.length() < len) {
            str = padStr + str;
        }
        return str;
    }
}
